<template>
  <div class="question">
    <van-dropdown-menu>
      <van-dropdown-item ref="dropdown">
        <template #title>
          <div class="title">
            <span class="name">面试宝典</span>
            {{ city }}
          </div>
        </template>
        <template #default>
          <van-index-bar :index-list="indexList">
            <div v-for="(value, key, index) in citys" :key="index">
              <van-index-anchor :index="key" class="anchor"
                >{{ key }}
              </van-index-anchor>
              <van-cell
                @click="cellClcik(item2)"
                v-for="(item2, index2) in value"
                :key="index2"
                :title="item2"
              ></van-cell>
            </div>
          </van-index-bar>
        </template>
      </van-dropdown-item>
    </van-dropdown-menu>
    <div class="content">
      <div class="position">
        <van-tag
          class="tag"
          v-for="(item, index) in cityPositions[city]"
          :key="index"
          :class="{ active: currIndex === index }"
          @click="currIndex = index"
          color="#f4f4f5"
          text-color="#8f8fa0"
          >{{ item.name }}</van-tag
        >
      </div>
    </div>
    <div class="middle">
      <div class="top">
        <div class="item1">
          <div class="item1-top">
            <i class="iconfont">&#xe64f;</i>
          </div>
          <div class="item1-bottom">常见错题</div>
        </div>
        <div class="item1">
          <div class="item1-top o2">
            <i class="iconfont ">&#xe654;</i>
          </div>
          <div class="item1-bottom">收藏题库</div>
        </div>
      </div>
      <div class="top mt33">
        <div class="item1">
          <div class="item1-top o3">
            <i class="iconfont ">&#xe648;</i>
          </div>
          <div class="item1-bottom">企业题库</div>
        </div>
        <div class="item1">
          <div class="item1-top o4">
            <i class="iconfont ">&#xe655;</i>
          </div>
          <div class="item1-bottom">已答题库</div>
        </div>
      </div>
      <div class="center">
        <van-circle
          class="circle"
          v-model="currRate"
          :rate="getRate(total)"
          :speed="10"
          layer-color="none"
          :color="gradientColor"
        >
          <div class="txt">
            <div>顺序刷题</div>
            <div>{{ getQuestion }}/{{ total }}</div>
          </div>
        </van-circle>
      </div>
    </div>
    <div class="bot">
      <div class="hh">累计收录</div>
      <div>{{ total.toLocaleString() }}</div>
    </div>
    <div class="bon">
      <van-button block color="#00b8d4" @click="btnClick">模拟面试</van-button>
    </div>
  </div>
</template>

<script>
import { interviewFilters } from '@/api/question.js'
import { mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters(['getQuestion', 'getRate'])
  },
  data () {
    return {
      city: '全国',
      indexList: [],
      citys: '',
      cityPositions: '',
      currIndex: 0,
      currRate: 0,
      total: 0,
      gradientColor: {
        '0%': 'rgba(228,1,55,0.3)',
        '100%': 'rgba(228,1,55,0.7)'
      }
    }
  },
  async created () {
    const res = await interviewFilters()
    this.citys = res.data.data.citys
    this.cityPositions = res.data.data.cityPositions
    this.indexList = Object.keys(res.data.data.citys)
    this.total = res.data.data.totalCount
    window.console.log(res)
  },
  mounted () {
    document.body.style.backgroundColor = '#f7f4f5'
  },
  beforeDestroy () {
    document.body.style.backgroundColor = '#fff'
  },
  methods: {
    cellClcik (str) {
      this.city = str
      this.$refs.dropdown.toggle()
      // 还原currIndex的值
      this.currIndex = 0
    },
    // 点击刷题时候利用路由传参
    btnClick () {
      const _id = this.cityPositions[this.city][this.currIndex].id
      this.$router.push('/home/questionInfo/' + _id + '?city=' + this.city)
    }
  }
}
</script>

<style lang="less" scopped>
.question {
  .title {
    font-size: 12px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: center;
    color: #545671;
    line-height: 12px;
    .name {
      padding-right: 8px;
      font-size: 18px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      text-align: left;
      color: #222222;
      line-height: 25px;
      letter-spacing: 0px;
    }
  }
  .anchor {
    background: #f7f4f5;
  }
  .content {
    padding: 25px @p15;
    background: #fff;
    .position {
      overflow: auto;
      display: flex;
      align-items: center;
      .tag {
        flex: 0 0 auto;
        padding: 5px 8px;
        margin-right: 15px;
        height: 28px;
        border-radius: 16px;
      }
      .active {
        background: #00b8d4 !important;
        color: #fff !important;
      }
    }
  }
  .middle {
    margin-top: 10px;
    background: #fff;
    padding: 16px 41px;
    position: relative;
    .top {
      display: flex;
      justify-content: space-between;
      .item1 {
        width: 50px;
        text-align: center;
        .item1-top {
          display: inline-block;
          width: 44px;
          height: 44px;
          border-radius: 50%;
          background: linear-gradient(180deg, #ff8080, #ff4949);
          text-align: center;
          line-height: 44px;
          .iconfont {
            font-size: 24px;
            color: #fff;
          }
        }
        .o2 {
          background: linear-gradient(180deg, #ffda05, #ffb302);
        }
        .o3 {
          background: linear-gradient(180deg, #00ddec, #00b8d4);
        }
        .o4 {
          background: linear-gradient(180deg, #3ee5b1, #1dc779);
        }
        .item1-bottom {
          display: inline-block;
          padding-top: 10px;
          text-align: center;
          font-size: 12px;
          font-weight: 400;
          color: #545671;
          line-height: 16px;
          width: 60px;
        }
      }
    }
    .mt33 {
      margin-top: 33px;
    }
    .center {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background-image: url(~@/assets/circle.png);
      width: 120px;
      height: 120px;
      background-size: 100%;
      .circle {
        width: 100% !important;
        height: 100% !important;
        padding: 8px;
        .txt {
          width: 100%;
          height: 100%;
          border-radius: 50%;
          color: #fff;
          font-size: 16px;
          padding-top: 30px;
          background: linear-gradient(
            rgba(228, 1, 55, 0.3),
            rgba(228, 1, 55, 0.7)
          );
        }
      }
    }
  }
  .bot {
    height: 130px;
    background: #fff;
    text-align: center;
    margin: 15px 0 15px 0;
    .hh {
      padding-top: 20px;
      padding-bottom: 20px;
      font-size: 18px;
      font-weight: 600;
      font-family: PingFangSC, PingFangSC-Semibold;
      text-align: center;
      color: #545671;
      line-height: 25px;
      letter-spacing: 0px;
    }
    div {
      font-size: 30px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      text-align: center;
      color: #545671;
      line-height: 42px;
      letter-spacing: 1px;
    }
  }
  .bon {
    padding: 0 @p15;
    .van-button {
      border-radius: 8px;
    }
  }
}
</style>
